<?php
namespace Home\Controller;
use Think\Controller;
class ShopController extends Controller {

    private $shop;

    public function _initialize() {
        $this->shop = D('Shop');
    }

    //申请店铺
    public function createShop() {
/*        if (IS_POST) {
            $license_img = I('post.license_img');
            $result = img_upload("license_img" ,"shop");
            $url = $result['path'] . $result['license_img'];

            if ($this->shop->create()) {
                $data = array(
                    'shop_name' => I('post.shop_name'),
                    'company' => I('post.company'),
                    'keeper' => I('post.keeper'),
                    'phone' => I('post.phone'),
                    'password' => sha1(trim(I('post.password'))),
                    'tel' => I('post.tel'),
                    'address' => I('post.address'),
                    'bank_no' => I('post.bank_no'),
                    'bank_user_name' => I('post.bank_user_name'),
                    'create_desc' => I('post.create_desc'),
                    'state' => I('post.state'),
                    'license_img' => $url,
                    'create_time' => time()
                );
                $bool = $this->shop->add($data);
                $this->ajaxReturn(1);
            } else {
                $error_info = $this->shop->getError();
                $this->ajaxReturn($error_info);
            }
        } else {
            $this->display();
        }*/

        if (IS_POST) {
/*            //手机
            $phone = to_int(I("post.phone"));
            if (!isMobile($phone)) {
                $this->error('请填写正确的手机号码!');
            }
            //验证重复性
            $ret = M('manager')->where(array('mobile'=>$phone))->find();
            if (!empty($res)||!empty($ret)) {
                $this->error("已有该手机号进行注册过");
            }
            $shop_name = I("post.shop_name");
            if (empty($shop_name)) {
                $this->error("店铺名称必需填写！");
            }
            $company = I("post.company");
            if (empty($company)) {
                $this->error("公司名称必需填写！");
            }
            $tel = trim(I("post.tel"));
            if (!islandline($tel)) {
                $this->error("固定电话格式不正确！");
            }
            $address = I("post.address");
            if (empty($address)) {
                $this->error("店铺地址必需填写！");
            }
            $bank_no = trim(I("post.bank_no"));
            if (empty($bank_no)&&is_numeric($bank_no)) {
                $this->error("请正确填写银行卡号");
            }
            $bank_user_name = I("post.bank_user_name");
            if (empty($bank_user_name)) {
                $this->error("银行卡号所有人必需填写！");
            }
            $license_img = I("post.license_img");
            if (empty($license_img)) {
                $this->error("营业执照必需上传！");
            }
            $id_img = I('post.id_img');
            if(empty($id_img)) {
                $this->error("店主身份证必需上传！");
            }
            $create_desc = I("post.create_desc");
            if (empty($create_desc)) {
                $this->error("开店说明必需填写！");
            }
            $shop_name = I("post.shop_name");
            if (empty($shop_name)) {
                $this->error("店铺名称必需填写！");
            }*/
            $data_one = array(
                'shop_name' => I('post.shop_name'),
                'company' => I('post.company'),
                'tel' => I('post.tel'),
                'address' => I('post.address'),
                'bank_no' => I('post.bank_no'),
                'bank_user_name' => I('post.bank_user_name'),
                'create_desc' => I('post.create_desc'),
                'state' => 1,
                'license_img' => I('post.license_img'),
                'id_img' => I('post.id_img'),
                'create_time' => time()
            );

            print_r($data_one);
            exit;


            $bool1 = M('shop')->add($data_one);
            $shop_id = M('shop')->getLastInsId();
            $keeper = I("post.keeper");
            if (!$keeper) {
                $this->error("店主必需填写！");
            }

            $salt = substr(md5(time() . $phone), -8);
            $password = md5(md5(I('post.password')) . $salt);
            $data_two = array(
                'shop_id' => $shop_id,
                'name' => $keeper,
                'mobile' => $phone,
                'salt' => $salt,
                'password' => $password
            );
            $bool2 = M('manager')->add($data_two);
            if ($bool1 && $bool2 == true) {
                $this->success('新增成功', U('Admin/shop/index'));
            } else {
                $this->error('提交失败!');
            }
        } else {
            $this->display();
        }









    }



}